#include "../../../common/mysql_user.hpp"
#include "../../../odb/user.hxx"
#include "user-odb.hxx"

#include <gflags/gflags.h>

// DEFINE_string(host, "127.0.0.1", "这是MySQL服务器地址");
// DEFINE_int32(port, 0, "这是MySQL服务器端口");
// DEFINE_string(db_name, "ChatRoom", "数据库默认库名称");
// DEFINE_string(user_name, "root", "MySQL用户名称");
// DEFINE_string(password, "Czh432248", "MySQL用户密码");
// DEFINE_string(cest, "utf8", "MySQL客户端字符集");
// DEFINE_int32(max_num, 3, "MySQL连接池最大连接数量");

void insert(bite_im::UserTable &table)
{
    auto user1 = std::make_shared<bite_im::User>("2022044026", "13147065653");
    auto user2 = std::make_shared<bite_im::User>("2024044026", "钟", "Czh432248");
    table.insert(user1);
    table.insert(user2);
}
bite_im::UserPtr select_by_id(bite_im::UserTable &table, const std::string &user_id)
{
    return table.select_by_id(user_id);
}
bite_im::UserPtr select_by_nickname(bite_im::UserTable &table, const std::string &nickname)
{
    return table.select_by_nickname(nickname);
}
bite_im::UserPtr select_by_phone(bite_im::UserTable &table, const std::string &phone)
{
    return table.select_by_phone(phone);
}
std::vector<bite_im::UserPtr> select_multi_users(bite_im::UserTable &table, const std::vector<std::string> &id_list)
{
    return table.select_multi_users(id_list);
}
void update(bite_im::UserTable &table)
{
    // // 测试单个select函数
    // auto user1 = select_by_id(table, "2022044026");
    // auto user2 = select_by_nickname(table, "钟");
    // auto user3 = select_by_phone(table, "13147065653");

    // std::cout << user3->user_id() << std::endl; // 测试select_by_phone成功

    std::vector<std::string> id_list = {"2022044026", "2024044026"};
    std::vector<bite_im::UserPtr> users = select_multi_users(table, id_list);
    auto user1 = users[0];
    auto user2 = users[1];
    user1->description("梧桐树只因哥");
    user2->description("藏起来的爱坤");
    table.update(user1);
    table.update(user2);
}

int main()
{
    // auto db = bite_im::ODBFactory::create(FLAGS_user_name, FLAGS_password, FLAGS_db_name,
    //                                       FLAGS_host, FLAGS_port, FLAGS_cest, FLAGS_max_num);
    auto db = bite_im::ODBFactory::create("root", "Czh432248", "ChatRoom",
                                          "127.0.0.1", 0, "utf8", 3);
    bite_im::UserTable table(db);
    // insert(table);
    update(table);
    return 0;
}